﻿using System.Linq;
using NHibernate.Linq;
using SharpArch.Domain.DomainModel;
using SharpArch.NHibernate;

namespace DevelopmentKit.Extensions.SharpArch.Repositorys
{
    /// <summary>
    /// 实体 仓储实现类
    /// </summary>
    /// <typeparam name="T">实体类型</typeparam>
    /// <typeparam name="TId">实体标识类型</typeparam>
    public class ENSRepositoryWithTypedId<T, TId> : NHibernateRepositoryWithTypedId<T, TId>, IENSRepositoryWithTypedId<T, TId> where T : EntityWithTypedId<TId>
    {
        /// <summary>
        /// 获取全部元素
        /// </summary>
        /// <returns>查询接口</returns>
        public IQueryable<T> FindAll()
        {
            return Session.Query<T>();
        }

        #region Implementation of IENSBaseRepositoryWithTypedId<T,TId>

        /// <summary>
        /// 获取子类 实体对象
        /// </summary>
        /// <typeparam name="TSub">子类 实体类型</typeparam>
        /// <param name="id">元素id</param>
        /// <returns>元素</returns>
        public TSub Get<TSub>(TId id) where TSub : T
        {
            return Session.Get<TSub>(id);
        }

        /// <summary>
        /// 获取所有子类实体列表查询列表
        /// </summary>
        /// <typeparam name="TSub">子类 实体类型</typeparam>
        /// <returns>查询接口</returns>
        public IQueryable<TSub> FindAll<TSub>()
        {
            return Session.Query<TSub>();
        }

        /// <summary>
        /// 获取子类 实体对象(非立即加载)
        /// </summary>
        /// <typeparam name="TSub">子类 实体类型</typeparam>
        /// <param name="id">元素id</param>
        /// <returns>元素</returns>
        public TSub Load<TSub>(TId id) where TSub : T
        {
            return Session.Load<TSub>(id);
        }
        #endregion
     

  }
}